<?php
require_once 'test-00-inc.php';

start('Core functionality examples');

test('element->tag returns tag[0] by default,
    but foreach(element->tag) iterates over the whole list:','
    $test = $html->head->meta
');
foreach (nz($test) as $key => $item) {
    echo $key, " => "; var_dump($item);
}

test('element could be cast to scalar
    (DOMNode::textContent by default):','
    (string)$html->body->p
');

test('$element->select() returns list
    which could be cast to scalar as well:','
    $html->body->select("p")->into($test)->items,
    (string)$test
');

test('How data from elements and lists differ:','
    $test = $html->body->p[1],
    (string)$test,
    (string)$test["class"],
    count($test), // # of children
    $html->body->select("p")->into($test)->items,
    (string)$test,
    count($test) // # of children
');

test('$element["attribute"] returns the object,
    which could be cast to scalar as well:','
    $html->head->meta["content"],
    (string)$html->head->meta[1]["content"]
');

test('elements could be counted:','
    count($html->body->p),
    count($html->body->select("p")),
    count($html->body->select("p")->items)
');

test('Children and parent elements can be found:','
    $html->body->ul->children(),
    $html->body->select("*/li")->items[0]->progenitor()
');

result($html);
